# coding=utf-8

import pygame
import sys
import os

pygame.init()

screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))

pygame.display.set_caption("2Dgame")

background_image = pygame.image.load("C://Users/admin/Documents/Visual Studio 2022/pygametext1-master/pygametext1-master/PythonApplication1/PythonApplication1/acc/bgm.png")

class Leaderboard:
    def __init__(self):
        self.scores = [(1,21)]

    def add_score(self, score):
        self.scores.append(score)

    def show(self):
        sorted_scores = sorted(self.scores, reverse=True)
        for i, score in enumerate(sorted_scores):
            print(f"{i + 1}. {score}")

class Button:
    def __init__(self, text, x, y, width, height, color, text_color):
        self.text = text
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.color = color
        self.text_color = text_color

    def draw(self, screen):
        pygame.draw.rect(screen, self.color, (self.x, self.y, self.width, self.height))
        font = pygame.font.Font(None, 36)
        text = font.render(self.text, True, self.text_color)
        screen.blit(text, (self.x + (self.width - text.get_width()) // 2, self.y + (self.height - text.get_height()) // 2))

    def is_clicked(self, pos):
        return self.x <= pos[0] <= self.x + self.width and self.y <= pos[1] <= self.y + self.height

start_button = Button("game", screen_width // 2 - 100, screen_height // 2 - 50, 200, 40, (135, 206, 235), (255, 255, 255))
leaderboard_button = Button("leaderboard", screen_width // 2 - 100, screen_height // 2 + 20, 200, 40, (135, 206, 235), (255, 255, 255))
settings_button = Button("set", screen_width // 2 - 100, screen_height // 2 + 90, 200, 40, (135, 206, 235), (255, 255, 255))
exit_button = Button("out", screen_width // 2 - 100, screen_height // 2 + 160, 200, 40, (135, 206, 235), (255, 255, 255))

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = pygame.mouse.get_pos()
            if start_button.is_clicked(pos):
                print("gamebegin")
                os.system("python C://Users/admin/Documents/Visual Studio 2022/pygametext1-master/pygametext1-master/PythonApplication1/PythonApplication1/PythonApplication1.py")
                running = False
            elif settings_button.is_clicked(pos):
                print("setup")
            elif exit_button.is_clicked(pos):
                running = False
            elif leaderboard_button.is_clicked(pos):
                print("leaderboard_buttonshow")
                leaderboard = Leaderboard()
                leaderboard.show()

    screen.blit(background_image, (0, 0))
    start_button.draw(screen)
    
    leaderboard_button.draw(screen)
    settings_button.draw(screen)
    exit_button.draw(screen)
    pygame.display.flip()

pygame.quit()
sys.exit()
